package com.kjtpay.design_pattern.state;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;

import com.kjtpay.design_pattern.R;
import com.kjtpay.design_pattern.observer.ObserverActivity;

public class StateActivity extends AppCompatActivity {

    public static void launch(Context context) {
        if (null != context) {
            Intent intent = new Intent();
            intent.setClass(context, StateActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    TimePicker timePicker;
    Switch finishSwitch;
    TextView stateTextView;
    Work testWork;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_state);
        setTitle("状态模式");

        finishSwitch = findViewById(R.id.switchFinish);
        timePicker = findViewById(R.id.timepicker);
        stateTextView = findViewById(R.id.textViewState);

        testWork = new Work();

        // 设置时间选择器状态
        timePicker.setIs24HourView(true);
        timePicker.setHour(9);
        timePicker.setMinute(0);
        // 设置点击事件不弹键盘
        timePicker.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
    }

    public void onButtonCheckClick(View view) {
        testWork.finish = finishSwitch.isChecked();
        testWork.hour = timePicker.getHour();
        testWork.minute = timePicker.getMinute();
        testWork.writeProgram();
        stateTextView.setText(testWork.current.show());
    }
}